package com.example.ustoreui;

import org.vaadin.easyuploads.UploadField;

import com.vaadin.ui.Button;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;

@SuppressWarnings("serial")
public class Upload extends Window {
	
	private UploadField uploadField;
	private Button uploadButton;
	
    public Upload() {
    	uploadField = new UploadField();
    	uploadField.setCaption("Selecione o arquivo a ser adicionado:");
    	uploadField.setButtonCaption("Escolher arquivo");
    	
    	uploadButton = new Button("Fazer Upload");
    	
    	buildUploadWindow();
    	uploadArquivo();
    }
    
    private void buildUploadWindow() {
    	this.setCaption("Upload de Arquivo");
    	this.center();
    	this.setWidth("500px");
    	this.setHeight("400px");
    	this.addComponent(uploadField);
    	this.addComponent(uploadButton);
    }
    
    private void uploadArquivo(){
    	uploadButton.addListener(new Button.ClickListener() {
    		public void buttonClick(ClickEvent event) {
    			Object value = uploadField.getValue();
    			getWindow().showNotification("Value:" + value);
    		}
    	});
    }
       
}
